package cn.yuanqiao.web.core.config;
/**
 * @author 赵常飞
 * @date 2024/7/19 16:31
 */

import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer;
import com.alibaba.fastjson.serializer.SerializeWriter;

import java.io.IOException;
import java.lang.reflect.Type;
import java.text.SimpleDateFormat;

/**
 *@Author: 赵常飞
 *@Date: 2024/7/19 16:31
 *@Description:
 *@Note:
 */

public class DateAsStringSerializer implements ObjectSerializer {
    @Override
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
        SerializeWriter out = serializer.getWriter();
        if (object != null) {
            SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            out.writeString(sdf.format(object));
        }
    }
}
